package com.ibm.workplace.wcm.cqplugin;

public class BugSeverity {

    public static final BugSeverity NONE = new BugSeverity("", "", 0);
    public static final BugSeverity ONE = new BugSeverity("Critical", "1", 1);
    public static final BugSeverity TWO = new BugSeverity("Major", "2", 2);
    public static final BugSeverity THREE = new BugSeverity("Average", "3", 3);
    public static final BugSeverity FOUR = new BugSeverity("Minor", "4", 4);

    private String code;
    private String description;
    private int value;

    private static BugSeverity[] BUG_SEVERITIES;

    static {
        BUG_SEVERITIES = new BugSeverity[] { NONE, ONE, TWO, THREE, FOUR };
    }

    private BugSeverity(String code, String description, int value) {
        super();

        this.code = code;
        this.description = description;
        this.value = value;
    }

    public String getDescription() {
        return description;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public boolean equals(Object o) {
        if (o != null && o instanceof BugSeverity) {
            return o == this || code.equalsIgnoreCase(((BugSeverity) o).getCode());
        } else {
            return false;
        }
    }

    public static BugSeverity getBugSeverityFromCode(String code) {
        if (code != null) {
            for (int i = 0; i < BUG_SEVERITIES.length; i++) {
                if (BUG_SEVERITIES[i].getCode().equals(code)) {
                    return BUG_SEVERITIES[i];
                }
            }
        }

        return NONE;
    }
    
    public String toString() {
        return value + "_" + code;
    }
}
